// pages/search/search.js
const app = getApp();
Page({
  data:{
    // list:[]
    list:[
      {
        province: "广东",
        city: "广州",
        district: "天河区",
        type: "sell",
        message: "哈士奇——拆家小能手，购买需谨慎！！"
      },
      {
        province: "安徽",
        city: "合肥",
        district: "庐州",
        type: "buy",
        message: "求购大型金毛犬，价格好商量~"
      },
      {
        province: "广东",
        city: "深圳",
        district: "南澳",
        type: "sell",
        message: "8只茶杯犬，稀罕得很，手慢无。"
      }
    ]
  },
  staticData: {
    inputValue:""
  },
  onLoad(){
    this.getSearchResult();
  },
  getSearchResult(){
    wx.request({
      //   url: 'https://nuanwan.wekeji.cn/student/index.php/trade/get_search_list', 
      url: 'https://api.ooopn.com/collect/360/api.php',
      data: {
        distinct: app.globalData.distinct,
        keyword: this.staticData.inputValue
      },
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: this.getSearchResultSucc.bind(this)
    })
  },
  getSearchResultSucc(res){
    if(res.data.ret){
      const result = res.data.data;
      this.setData({
        list: result
      })
    }else{
      this.setData({
        list: []
      })
    }
   
  },
  handleInputChange(e) {
    this.staticData.inputValue=e.detail.value;
  },
  handleSearch(){
    this.getSearchResult()
  },
  handleItemTap(e){
    wx.navigateTo({
      url: '/pages/detail/detail?id=' + e.currentTarget.id
    })
  },

  onShareAppMessage() {
    return {
      title: "萌宠交易平台",
      path: '/pages/search/search'
    }
  },
})